package com.base;

import org.joda.time.DateTime;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.Calendar;
import java.util.concurrent.TimeUnit;

/**
 * @author: sun.hongliang
 * @create: 2018/06/12 12:13
 */
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public class JMHTest {

    private static final long minuts = 24 * 60 * 60 * 1000;

    public static void main(String[] args) {
        try {
            Options options = new OptionsBuilder().include(JMHTest.class.getName()).forks(1).build();
            new Runner(options).run();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Benchmark
    @Threads(5)
    public void runCalendar() {
        Calendar calendar = Calendar.getInstance();
    }

    @Benchmark
    @Threads(5)
    public void runJoda() {
        DateTime dateTime = new DateTime();
    }

    @Benchmark
    @Threads(5)
    public void runSystem() {
        long system = System.currentTimeMillis() / minuts;
    }
}
